<?php

require_once( '../system/smarty.inc' );

require_once( '../system/tdao/Class_T_PATTERN.php' );
require_once( '../system/mdao/Class_M_OTHER.php' );

require_once( '../system/Class_ERROR.php' );
require_once( '../system/login.inc.php' );
require_once( '../system/aoki_m.php' );
require_once( '../system/Class_PWD.php' );

Class_PWD::valid_auth(AOKI_AUTH_T_PATTERN,$login['staff_auth']);

if   ($login['staff_auth'] == 'G-2' || $login['staff_auth'] == 'G-3')  {
	echo "権限はありません";
	exit;
}
$dosearch = FALSE ;

$phase = 'input';

if ( isset( $_GET['csv'] ) &&  (  $_GET['csv'] == "copy" ) ) {
	$dao = new Class_T_PATTERN;
	$matrix_cd = $_GET['matrix_cd'] ;
	if ($matrix_cd) {
		$dao->setTableNameWeek($matrix_cd);
	}
	$matrix_cdt =  $_GET['matrix_cdt'] ;
	if ($dao->copyto($matrix_cdt)){
		$message = "店別配布明細の登録が完了しました";
	}else {
		$message = "店別配布明細の登録が失敗しました";
	}
	$phase = 'complete';
}



//---CSVダウンロード　処理完了
$isG6_7 = FALSE;
if   ($login['staff_auth'] == 'G-6' || $login['staff_auth'] == 'G-7' || $login['staff_auth'] == 'G-4')  {
	$isG6_7 = TRUE;
}
//==================================周
if (empty($forms["year4"])) {
	$forms["year4"] = date('Y');
}
$smarty->assign('year4',  Class_PWD::get_years());

$week = Class_M_OTHER::get_week_array( $forms["year4"], PLEASE_SELECT_ARR, TRUE );

$smarty->assign('week', $week );

if (empty($forms["year4t"])) {
	$forms["year4t"] = date('Y');
}
$smarty->assign('year4t',  Class_PWD::get_years());

$weekt = Class_M_OTHER::get_week_array( $forms["year4t"], PLEASE_SELECT_ARR, TRUE );

$smarty->assign('weekt', $weekt );



$smarty->assign('forms',  $forms);



//==================================周
 $smarty->assign('message',  $message );
$smarty->assign('phase',  $phase );
$smarty->assign('isG6_7', $isG6_7 );

$smarty->assign('menu', $smarty->fetch('menu.html') );
$smarty->assign('logout', $smarty->fetch('logout.html') );
$smarty->assign('footer', $smarty->fetch('footer.html') );
//$smarty->assign('pageing', $smarty->fetch('page.html') );
$smarty->display('tpattern_copy.html');

?>